﻿using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Algorithm_api.calculate.StrongLine
{
    public class MyMap
    {


        public List<string> GetStrongLine(Graph g)
        {
            //两次dfs查询
            List<string> results = new List<string>();
            ArrayList<int> finished = new ArrayList<int>();
            for(int i = 0; i < g.size; i++) // 第一次dfs遍历 查找死端序列
            {
                if (!g.visited[i])
                {
                    g.dfs(i, null, finished);
                }
            }

            ArrayList<int> component = new ArrayList<int>();
            g.ResetVisited();

            foreach(int f in finished) //根据死端序列进行dfs遍历 查询强联通分量
            {
                if (!g.visited[f])
                {
                    string sequence = "";
                    g.dfs(f, component, null);
                    foreach(int d in component)
                    {
                        if(!sequence.Contains(g.vtcName[d]))
                            sequence = sequence + g.vtcName[d];
                    }

                    results.Add(sequence);
                    component = new ArrayList<int>();
                }
            }
            return results;
        }
    }
}
